﻿using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebServerConnectorDll;

namespace FridgeManagerApp
{
    class DeviceTypeInsertViewModel : NotificationObject
    {
        DeviceTypeInsert gWindow;
        DeviceTypeViewModel gParentViewModel;

        public DeviceTypeInsertViewModel(DeviceTypeInsert pWindow, DeviceTypeViewModel pParentViewModel)
        {
            gWindow = pWindow;
            gParentViewModel = pParentViewModel;
        }

        private String deviceTypeName;
        public String DeviceTypeName
        {
            get
            {
                return deviceTypeName;
            }
            set
            {
                deviceTypeName = value;
                RaisePropertyChanged("DeviceTypeName");
            }
        }

        private String deviceStructure;
        public String DeviceStructure
        {
            get
            {
                return deviceStructure;
            }
            set
            {
                deviceStructure = value;
                RaisePropertyChanged("DeviceStructure");
            }
        }

        private int deviceVolume;
        public int DeviceVolume
        {
            get
            {
                return deviceVolume;
            }
            set
            {
                deviceVolume = value;
                RaisePropertyChanged("DeviceVolume");
            }
        }

        private String deviceSize;
        public String DeviceSize
        {
            get
            {
                return deviceSize;
            }
            set
            {
                deviceSize = value;
                RaisePropertyChanged("DeviceSize");
            }
        }

        private String hasee;
        public String Hasee
        {
            get
            {
                return hasee;
            }
            set
            {
                hasee = value;
                RaisePropertyChanged("Hasee");
            }
        }
        protected DelegateCommand<object> insertCommand;
        public DelegateCommand<object> InsertCommand
        {
            get
            {
                return insertCommand ?? (insertCommand = new DelegateCommand<object>(AInsertCommand, BInsertCommand));
            }
        }

        protected virtual void AInsertCommand(object obj)
        {
            List<WDeviceType> list = new List<WDeviceType>();
            WDeviceType item = new WDeviceType();
            item.DeviceTypeName = DeviceTypeName;
            item.DeviceStructure = DeviceStructure;
            item.DeviceVolume = DeviceVolume;
            item.DeviceSize = DeviceSize;
            item.Hasee = Hasee;
            list.Add(item);
            HttpResponse response = WDeviceType.Insert(list);

            gWindow.Close();
            gParentViewModel.UpdateList();
        }

        private bool BInsertCommand(object arg)
        {
            return true;
        }

        protected DelegateCommand<object> quitCommand;
        public DelegateCommand<object> QuitCommand
        {
            get
            {
                return quitCommand ?? (quitCommand = new DelegateCommand<object>(AQuitCommand, BQuitCommand));
            }
        }

        protected virtual void AQuitCommand(object obj)
        {
            gWindow.Close();
            gParentViewModel.UpdateList();
        }

        private bool BQuitCommand(object arg)
        {
            return true;
        }
    }
}
